<template>
  <div>
    <el-dialog :visible.sync="formVisible" @close="hide" width='654px' :show-close='false'>
      <div slot="title" class="dialog-title">提现审核</div>
      <el-card class="el-card-border">
        <el-form :ref="formName" :model="formFieldsData" label-width='120px' :label-position="labelPosition">
          <el-form-item label="用户：">
            <p v-if="details">{{details.user_info.username}}/{{details.user_info.mobile}}</p>
          </el-form-item>
          <el-form-item label="可提现金额：">
            <p v-if="details">￥{{details.account_info.balance}}</p>
          </el-form-item>
          <el-form-item label="申请提现金额：" >
            <p v-if="details">￥{{details.account_info.withdrawal_in}}</p>
          </el-form-item>
          <el-form-item label="申请时间：">
            <p>￥{{details.create_time}}</p>
          </el-form-item>
          <p>用户流水：</p>
          <el-table
            :data="details.records_log"
            style="width: 100%;margin: 20px 0;"
            row-key="id"
            border
            default-expand-all
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          >
            <el-table-column label="操作类型"  align='center'>
              <template slot-scope="item">
                <p>{{getFromType(item.row)}}</p>
              </template>
            </el-table-column>
            <el-table-column label="金额" prop='count_number' align='center'/>
            <el-table-column label="状态" align='center'>
              <template slot-scope="item">
                <p>{{item.row.sign==0?'出账':'入账'}}</p>
              </template>
            </el-table-column>
            <el-table-column label="操作时间" prop='create_time' align='center'/>
          </el-table>
          <p>账户冻结记录：</p>
          <el-table
            :data="details.action_log"
            style="width: 100%;margin: 20px 0;"
            row-key="id"
            border
            default-expand-all
            :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          >
            <el-table-column label="操作类型"  align='center'>
              <template slot-scope="item">
                <p>{{getActionType(item.row)}}</p>
              </template>
            </el-table-column>
            <el-table-column label="冻结金额" prop='money' align='center'/>
            <el-table-column label="操作时间" prop='create_time' align='center'/>
            <el-table-column label="备注" prop='remake' align='center'/>
          </el-table>
          <el-form-item label="审核：" prop="status">
            <el-select v-model="formFieldsData.status" placeholder="请选择" style="width: 92%">
              <el-option
                v-for="(item,key) in statusList"
                :key="key"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="驳回原因：" prop="remake" v-if="formFieldsData.status==2">
            <el-input type="textarea" v-model="formFieldsData.remake" style="width: 92%"></el-input>
          </el-form-item>
        </el-form>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button @click="hide" size='medium'>取 消</el-button>
        <el-button type="primary" @click="handleSubmit" size='medium'>确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'

export default {
  props: {
    url:{
      type:String,
      default:''
    }
  },
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      list:[
        {id:1,full_name:'张三',mobile_code:18735365265,value_list:[],post:'司机',source:'',time:'2020-11-17',tuiguang:'aa',status:'1'}
      ],
      formName:'withdrawal',
      formFieldsData:{
        id:'',
        status:'',
        remake:'',
      },
      statusList:[
        {id:'0',name:'待审核'},
        {id:'1',name:'审核通过'},
        {id:'2',name:'审核驳回'}
      ], // 审核状态
      details:'',
      actions:[
        {label:'冻结金额',id:1},
        {label:'提现',id:2},
        {label:'简历',id:3},
        {label:'企业',id:4},
        {label:'岗位',id:5}
      ],
      froms:[
        {label:'注册账号',id:1},
        {label:'发布简历',id:2},
        {label:'浏览岗位',id:3},
        {label:'提现',id:100},
        {label:'拒绝提现返回用户余额',id:101}
      ],
    }
  },
  methods: {
    // 获取列表
    getList() {
      console.log(this.queryParam)
    },
    // 提现审核
    show(item) {
      this.formVisible = true
      this.$http.get('/user/admin/Withdraw/'+item.uid).then(response => {
        this.details = response.data.data || response.data
      })
      this.formFieldsData.id = item.id
    },
    // 隐藏弹框
    hide() {
      this.formVisible = false
    },
    // 获取冻结记录的操作类型
    getActionType(item) {
      let idx = this.actions.findIndex(res=>{
        return res.id == item.action_type
      })
      return idx>-1?this.actions[idx].label:''
    },
    // 获取收支流水操作类型
    getFromType(item) {
      let idx = this.froms.findIndex(res=>{
        return res.id == item.from_type
      })
      return idx>-1?this.froms[idx].label:''
    },
    handleSubmit() {
      if (this.formFieldsData.status==0) return
      this.$http.put(this.url+'/'+this.formFieldsData.id,this.formFieldsData).then(response => {
        if (response.code === 10000) {
          this.$message.success(response.message)
          this.hide()
          this.$emit('success')
        } else {
          this.$message.error(response.message)
        }
      })
    }
  }
}
</script>
<style>
  .details .el-dialog__body{
    height: 700px;
    overflow-y: auto;
  }
</style>
<style lang="scss" scoped>
  .backUp{
    flex:1;
    min-width: 0;
    text-align: left;
    margin-bottom:10px;
  }
  .title{
    font-size: 16px;
    margin-bottom:10px;
  }
  .info{
    line-height: 30px;
  }
  .img_box{
    text-align: center;
  }
  .job_list{
    border:1px solid #eee;
    padding: 10px;
    border-radius: 4px;
  }
  .wages{
    margin-bottom: 20px;
  }
</style>